<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>pgmpy.models.FactorGraph &#8212; pgmpy 0.1.2 documentation</title>
    
    <link rel="stylesheet" href="../../../_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../../',
        VERSION:     '0.1.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pgmpy 0.1.2 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../../index.html">
              <img class="logo" src="../../../_static/logo.png" alt="Logo"/>
            </a></p>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="../../../search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <h1>Source code for pgmpy.models.FactorGraph</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/env python3</span>

<span class="kn">import</span> <span class="nn">itertools</span>
<span class="kn">from</span> <span class="nn">collections</span> <span class="k">import</span> <span class="n">defaultdict</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">networkx.algorithms</span> <span class="k">import</span> <span class="n">bipartite</span>

<span class="kn">from</span> <span class="nn">pgmpy.models.MarkovModel</span> <span class="k">import</span> <span class="n">MarkovModel</span>
<span class="kn">from</span> <span class="nn">pgmpy.base</span> <span class="k">import</span> <span class="n">UndirectedGraph</span>
<span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">DiscreteFactor</span>
<span class="kn">from</span> <span class="nn">pgmpy.factors</span> <span class="k">import</span> <span class="n">factor_product</span>
<span class="kn">from</span> <span class="nn">pgmpy.extern.six.moves</span> <span class="k">import</span> <span class="nb">filter</span><span class="p">,</span> <span class="nb">range</span><span class="p">,</span> <span class="nb">zip</span>


<div class="viewcode-block" id="FactorGraph"><a class="viewcode-back" href="../../../models.html#pgmpy.models.FactorGraph.FactorGraph">[docs]</a><span class="k">class</span> <span class="nc">FactorGraph</span><span class="p">(</span><span class="n">UndirectedGraph</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class for representing factor graph.</span>

<span class="sd">    DiscreteFactor graph is a bipartite graph representing factorization of a function.</span>
<span class="sd">    They allow efficient computation of marginal distributions through sum-product</span>
<span class="sd">    algorithm.</span>

<span class="sd">    A factor graph contains two types of nodes. One type corresponds to random</span>
<span class="sd">    variables whereas the second type corresponds to factors over these variables.</span>
<span class="sd">    The graph only contains edges between variables and factor nodes. Each factor</span>
<span class="sd">    node is associated with one factor whose scope is the set of variables that</span>
<span class="sd">    are its neighbors.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    data: input graph</span>
<span class="sd">        Data to initialize graph. If data=None (default) an empty graph is</span>
<span class="sd">        created. The data is an edge list.</span>

<span class="sd">    Examples</span>
<span class="sd">    --------</span>
<span class="sd">    Create an empty FactorGraph with no nodes and no edges</span>

<span class="sd">    &gt;&gt;&gt; from pgmpy.models import FactorGraph</span>
<span class="sd">    &gt;&gt;&gt; G = FactorGraph()</span>

<span class="sd">    G can be grown by adding variable nodes as well as factor nodes</span>

<span class="sd">    **Nodes:**</span>

<span class="sd">    Add a node at a time or a list of nodes.</span>

<span class="sd">    &gt;&gt;&gt; G.add_node(&#39;a&#39;)</span>
<span class="sd">    &gt;&gt;&gt; G.add_nodes_from([&#39;a&#39;, &#39;b&#39;])</span>
<span class="sd">    &gt;&gt;&gt; phi1 = DiscreteFactor([&#39;a&#39;, &#39;b&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">    &gt;&gt;&gt; G.add_factors(phi1)</span>
<span class="sd">    &gt;&gt;&gt; G.add_nodes_from([phi1])</span>

<span class="sd">    **Edges:**</span>

<span class="sd">    G can also be grown by adding edges.</span>

<span class="sd">    &gt;&gt;&gt; G.add_edge(&#39;a&#39;, phi1)</span>

<span class="sd">    or a list of edges</span>

<span class="sd">    &gt;&gt;&gt; G.add_edges_from([(&#39;a&#39;, phi1), (&#39;b&#39;, phi1)])</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ebunch</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">FactorGraph</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">ebunch</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">(</span><span class="n">ebunch</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">factors</span> <span class="o">=</span> <span class="p">[]</span>

<div class="viewcode-block" id="FactorGraph.add_edge"><a class="viewcode-back" href="../../../models.html#pgmpy.models.FactorGraph.FactorGraph.add_edge">[docs]</a>    <span class="k">def</span> <span class="nf">add_edge</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">u</span><span class="p">,</span> <span class="n">v</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add an edge between variable_node and factor_node.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        u, v: nodes</span>
<span class="sd">            Nodes can be any hashable Python object.</span>

<span class="sd">        Examples</span>
<span class="sd">        --------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.models import FactorGraph</span>
<span class="sd">        &gt;&gt;&gt; G = FactorGraph()</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([&#39;a&#39;, &#39;b&#39;, &#39;c&#39;])</span>
<span class="sd">        &gt;&gt;&gt; phi1 = DiscreteFactor([&#39;a&#39;, &#39;b&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([phi1, phi2])</span>
<span class="sd">        &gt;&gt;&gt; G.add_edge(&#39;a&#39;, phi1)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">u</span> <span class="o">!=</span> <span class="n">v</span><span class="p">:</span>
            <span class="nb">super</span><span class="p">(</span><span class="n">FactorGraph</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="n">u</span><span class="p">,</span> <span class="n">v</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Self loops are not allowed&#39;</span><span class="p">)</span></div>

<div class="viewcode-block" id="FactorGraph.add_factors"><a class="viewcode-back" href="../../../models.html#pgmpy.models.FactorGraph.FactorGraph.add_factors">[docs]</a>    <span class="k">def</span> <span class="nf">add_factors</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">factors</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Associate a factor to the graph.</span>
<span class="sd">        See factors class for the order of potential values.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        *factor: pgmpy.factors.DiscreteFactor object</span>
<span class="sd">            A factor object on any subset of the variables of the model which</span>
<span class="sd">            is to be associated with the model.</span>

<span class="sd">        Examples</span>
<span class="sd">        --------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.models import FactorGraph</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.factors.discrete import DiscreteFactor</span>
<span class="sd">        &gt;&gt;&gt; G = FactorGraph()</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([&#39;a&#39;, &#39;b&#39;, &#39;c&#39;])</span>
<span class="sd">        &gt;&gt;&gt; phi1 = DiscreteFactor([&#39;a&#39;, &#39;b&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; phi2 = DiscreteFactor([&#39;b&#39;, &#39;c&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; G.add_factors(phi1, phi2)</span>
<span class="sd">        &gt;&gt;&gt; G.add_edges_from([(&#39;a&#39;, phi1), (&#39;b&#39;, phi1),</span>
<span class="sd">        ...                   (&#39;b&#39;, phi2), (&#39;c&#39;, phi2)])</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">factor</span> <span class="ow">in</span> <span class="n">factors</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">set</span><span class="p">(</span><span class="n">factor</span><span class="o">.</span><span class="n">variables</span><span class="p">)</span> <span class="o">-</span> <span class="nb">set</span><span class="p">(</span><span class="n">factor</span><span class="o">.</span><span class="n">variables</span><span class="p">)</span><span class="o">.</span><span class="n">intersection</span><span class="p">(</span>
                    <span class="nb">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodes</span><span class="p">())):</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Factors defined on variable not in the model&quot;</span><span class="p">,</span>
                                 <span class="n">factor</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">factors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">factor</span><span class="p">)</span></div>

<div class="viewcode-block" id="FactorGraph.remove_factors"><a class="viewcode-back" href="../../../models.html#pgmpy.models.FactorGraph.FactorGraph.remove_factors">[docs]</a>    <span class="k">def</span> <span class="nf">remove_factors</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">factors</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Removes the given factors from the added factors.</span>

<span class="sd">        Examples</span>
<span class="sd">        --------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.models import FactorGraph</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.factors.discrete import DiscreteFactor</span>
<span class="sd">        &gt;&gt;&gt; G = FactorGraph()</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([&#39;a&#39;, &#39;b&#39;, &#39;c&#39;])</span>
<span class="sd">        &gt;&gt;&gt; phi1 = DiscreteFactor([&#39;a&#39;, &#39;b&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; G.add_factors(phi1)</span>
<span class="sd">        &gt;&gt;&gt; G.remove_factors(phi1)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">factor</span> <span class="ow">in</span> <span class="n">factors</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">factors</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">factor</span><span class="p">)</span></div>

<div class="viewcode-block" id="FactorGraph.get_cardinality"><a class="viewcode-back" href="../../../models.html#pgmpy.models.FactorGraph.FactorGraph.get_cardinality">[docs]</a>    <span class="k">def</span> <span class="nf">get_cardinality</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the cardinality of the node</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        node: any hashable python object (optional)</span>
<span class="sd">            The node whose cardinality we want. If node is not specified returns a</span>
<span class="sd">            dictionary with the given variable as keys and their respective cardinality</span>
<span class="sd">            as values.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        int or dict : If node is specified returns the cardinality of the node.</span>
<span class="sd">                      If node is not specified returns a dictionary with the given</span>
<span class="sd">                      variable as keys and their respective cardinality as values.</span>

<span class="sd">        Examples</span>
<span class="sd">        --------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.models import FactorGraph</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.factors import DiscreteFactor</span>
<span class="sd">        &gt;&gt;&gt; G = FactorGraph()</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([&#39;a&#39;, &#39;b&#39;, &#39;c&#39;])</span>
<span class="sd">        &gt;&gt;&gt; phi1 = DiscreteFactor([&#39;a&#39;, &#39;b&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; phi2 = DiscreteFactor([&#39;b&#39;, &#39;c&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([phi1, phi2])</span>
<span class="sd">        &gt;&gt;&gt; G.add_edges_from([(&#39;a&#39;, phi1), (&#39;b&#39;, phi1),</span>
<span class="sd">        ...                   (&#39;b&#39;, phi2), (&#39;c&#39;, phi2)])</span>
<span class="sd">        &gt;&gt;&gt; G.add_factors(phi1, phi2)</span>
<span class="sd">        &gt;&gt;&gt; G.get_cardinality()</span>
<span class="sd">            defaultdict(&lt;class &#39;int&#39;&gt;, {&#39;c&#39;: 2, &#39;b&#39;: 2, &#39;a&#39;: 2})</span>

<span class="sd">        &gt;&gt;&gt; G.get_cardinality(&#39;a&#39;)</span>
<span class="sd">            2</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">node</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">factor</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">factors</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">variable</span><span class="p">,</span> <span class="n">cardinality</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">factor</span><span class="o">.</span><span class="n">scope</span><span class="p">(),</span> <span class="n">factor</span><span class="o">.</span><span class="n">cardinality</span><span class="p">):</span>
                    <span class="k">if</span> <span class="n">node</span> <span class="o">==</span> <span class="n">variable</span><span class="p">:</span>
                        <span class="k">return</span> <span class="n">cardinality</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">cardinalities</span> <span class="o">=</span> <span class="n">defaultdict</span><span class="p">(</span><span class="nb">int</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">factor</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">factors</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">variable</span><span class="p">,</span> <span class="n">cardinality</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">factor</span><span class="o">.</span><span class="n">scope</span><span class="p">(),</span> <span class="n">factor</span><span class="o">.</span><span class="n">cardinality</span><span class="p">):</span>
                    <span class="n">cardinalities</span><span class="p">[</span><span class="n">variable</span><span class="p">]</span> <span class="o">=</span> <span class="n">cardinality</span>
            <span class="k">return</span> <span class="n">cardinalities</span></div>

<div class="viewcode-block" id="FactorGraph.check_model"><a class="viewcode-back" href="../../../models.html#pgmpy.models.FactorGraph.FactorGraph.check_model">[docs]</a>    <span class="k">def</span> <span class="nf">check_model</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Check the model for various errors. This method checks for the following</span>
<span class="sd">        errors. In the same time it also updates the cardinalities of all the</span>
<span class="sd">        random variables.</span>

<span class="sd">        * Check whether bipartite property of factor graph is still maintained</span>
<span class="sd">          or not.</span>
<span class="sd">        * Check whether factors are associated for all the random variables or not.</span>
<span class="sd">        * Check if factors are defined for each factor node or not.</span>
<span class="sd">        * Check if cardinality information for all the variables is availble or not.</span>
<span class="sd">        * Check if cardinality of random variable remains same across all the</span>
<span class="sd">          factors.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">variable_nodes</span> <span class="o">=</span> <span class="nb">set</span><span class="p">([</span><span class="n">x</span> <span class="k">for</span> <span class="n">factor</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">factors</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">factor</span><span class="o">.</span><span class="n">scope</span><span class="p">()])</span>
        <span class="n">factor_nodes</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodes</span><span class="p">())</span> <span class="o">-</span> <span class="n">variable_nodes</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="nb">all</span><span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">factor_node</span><span class="p">,</span> <span class="n">DiscreteFactor</span><span class="p">)</span> <span class="k">for</span> <span class="n">factor_node</span> <span class="ow">in</span> <span class="n">factor_nodes</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Factors not associated for all the random variables&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="p">(</span><span class="ow">not</span> <span class="p">(</span><span class="n">bipartite</span><span class="o">.</span><span class="n">is_bipartite</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span> <span class="ow">or</span>
            <span class="ow">not</span> <span class="p">(</span><span class="n">bipartite</span><span class="o">.</span><span class="n">is_bipartite_node_set</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">variable_nodes</span><span class="p">)</span> <span class="ow">or</span>
                 <span class="n">bipartite</span><span class="o">.</span><span class="n">is_bipartite_node_set</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">variable_nodes</span><span class="p">))):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Edges can only be between variables and factors&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">factor_nodes</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">factors</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Factors not associated with all the factor nodes.&#39;</span><span class="p">)</span>

        <span class="n">cardinalities</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cardinality</span><span class="p">()</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">variable_nodes</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">cardinalities</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Factors for all the variables not defined&#39;</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">factor</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">factors</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">variable</span><span class="p">,</span> <span class="n">cardinality</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">factor</span><span class="o">.</span><span class="n">scope</span><span class="p">(),</span> <span class="n">factor</span><span class="o">.</span><span class="n">cardinality</span><span class="p">):</span>
                <span class="k">if</span> <span class="p">(</span><span class="n">cardinalities</span><span class="p">[</span><span class="n">variable</span><span class="p">]</span> <span class="o">!=</span> <span class="n">cardinality</span><span class="p">):</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Cardinality of variable </span><span class="si">{var}</span><span class="s1"> not matching among factors&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">var</span><span class="o">=</span><span class="n">variable</span><span class="p">))</span>

        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="FactorGraph.get_variable_nodes"><a class="viewcode-back" href="../../../models.html#pgmpy.models.FactorGraph.FactorGraph.get_variable_nodes">[docs]</a>    <span class="k">def</span> <span class="nf">get_variable_nodes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns variable nodes present in the graph.</span>

<span class="sd">        Before calling this method make sure that all the factors are added</span>
<span class="sd">        properly.</span>

<span class="sd">        Examples</span>
<span class="sd">        --------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.models import FactorGraph</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.factors.discrete import DiscreteFactor</span>
<span class="sd">        &gt;&gt;&gt; G = FactorGraph()</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([&#39;a&#39;, &#39;b&#39;, &#39;c&#39;])</span>
<span class="sd">        &gt;&gt;&gt; phi1 = DiscreteFactor([&#39;a&#39;, &#39;b&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; phi2 = DiscreteFactor([&#39;b&#39;, &#39;c&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([phi1, phi2])</span>
<span class="sd">        &gt;&gt;&gt; G.add_factors(phi1, phi2)</span>
<span class="sd">        &gt;&gt;&gt; G.add_edges_from([(&#39;a&#39;, phi1), (&#39;b&#39;, phi1),</span>
<span class="sd">        ...                   (&#39;b&#39;, phi2), (&#39;c&#39;, phi2)])</span>
<span class="sd">        &gt;&gt;&gt; G.get_variable_nodes()</span>
<span class="sd">        [&#39;a&#39;, &#39;b&#39;]</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">check_model</span><span class="p">()</span>

        <span class="n">variable_nodes</span> <span class="o">=</span> <span class="nb">set</span><span class="p">([</span><span class="n">x</span> <span class="k">for</span> <span class="n">factor</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">factors</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">factor</span><span class="o">.</span><span class="n">scope</span><span class="p">()])</span>
        <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="n">variable_nodes</span><span class="p">)</span></div>

<div class="viewcode-block" id="FactorGraph.get_factor_nodes"><a class="viewcode-back" href="../../../models.html#pgmpy.models.FactorGraph.FactorGraph.get_factor_nodes">[docs]</a>    <span class="k">def</span> <span class="nf">get_factor_nodes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns factors nodes present in the graph.</span>

<span class="sd">        Before calling this method make sure that all the factors are added</span>
<span class="sd">        properly.</span>

<span class="sd">        Examples</span>
<span class="sd">        --------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.models import FactorGraph</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.factors.discrete import DiscreteFactor</span>
<span class="sd">        &gt;&gt;&gt; G = FactorGraph()</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([&#39;a&#39;, &#39;b&#39;, &#39;c&#39;])</span>
<span class="sd">        &gt;&gt;&gt; phi1 = DiscreteFactor([&#39;a&#39;, &#39;b&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; phi2 = DiscreteFactor([&#39;b&#39;, &#39;c&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([phi1, phi2])</span>
<span class="sd">        &gt;&gt;&gt; G.add_factors(phi1, phi2)</span>
<span class="sd">        &gt;&gt;&gt; G.add_edges_from([(&#39;a&#39;, phi1), (&#39;b&#39;, phi1),</span>
<span class="sd">        ...                   (&#39;b&#39;, phi2), (&#39;c&#39;, phi2)])</span>
<span class="sd">        &gt;&gt;&gt; G.get_factor_nodes()</span>
<span class="sd">        [&lt;DiscreteFactor representing phi(b:2, c:2) at 0x4b8c7f0&gt;,</span>
<span class="sd">         &lt;DiscreteFactor representing phi(a:2, b:2) at 0x4b8c5b0&gt;]</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">check_model</span><span class="p">()</span>

        <span class="n">variable_nodes</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_variable_nodes</span><span class="p">()</span>
        <span class="n">factor_nodes</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodes</span><span class="p">())</span> <span class="o">-</span> <span class="nb">set</span><span class="p">(</span><span class="n">variable_nodes</span><span class="p">)</span>
        <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="n">factor_nodes</span><span class="p">)</span></div>

<div class="viewcode-block" id="FactorGraph.to_markov_model"><a class="viewcode-back" href="../../../models.html#pgmpy.models.FactorGraph.FactorGraph.to_markov_model">[docs]</a>    <span class="k">def</span> <span class="nf">to_markov_model</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Converts the factor graph into markov model.</span>

<span class="sd">        A markov model contains nodes as random variables and edge between</span>
<span class="sd">        two nodes imply interaction between them.</span>

<span class="sd">        Examples</span>
<span class="sd">        --------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.models import FactorGraph</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.factors.discrete import DiscreteFactor</span>
<span class="sd">        &gt;&gt;&gt; G = FactorGraph()</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([&#39;a&#39;, &#39;b&#39;, &#39;c&#39;])</span>
<span class="sd">        &gt;&gt;&gt; phi1 = DiscreteFactor([&#39;a&#39;, &#39;b&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; phi2 = DiscreteFactor([&#39;b&#39;, &#39;c&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; G.add_factors(phi1, phi2)</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([phi1, phi2])</span>
<span class="sd">        &gt;&gt;&gt; G.add_edges_from([(&#39;a&#39;, phi1), (&#39;b&#39;, phi1),</span>
<span class="sd">        ...                   (&#39;b&#39;, phi2), (&#39;c&#39;, phi2)])</span>
<span class="sd">        &gt;&gt;&gt; mm = G.to_markov_model()</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">mm</span> <span class="o">=</span> <span class="n">MarkovModel</span><span class="p">()</span>

        <span class="n">variable_nodes</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_variable_nodes</span><span class="p">()</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodes</span><span class="p">())</span> <span class="o">-</span> <span class="nb">set</span><span class="p">(</span><span class="n">variable_nodes</span><span class="p">))</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">factors</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Factors not associated with all the factor nodes.&#39;</span><span class="p">)</span>

        <span class="n">mm</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">(</span><span class="n">variable_nodes</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">factor</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">factors</span><span class="p">:</span>
            <span class="n">scope</span> <span class="o">=</span> <span class="n">factor</span><span class="o">.</span><span class="n">scope</span><span class="p">()</span>
            <span class="n">mm</span><span class="o">.</span><span class="n">add_edges_from</span><span class="p">(</span><span class="n">itertools</span><span class="o">.</span><span class="n">combinations</span><span class="p">(</span><span class="n">scope</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
            <span class="n">mm</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="n">factor</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">mm</span></div>

<div class="viewcode-block" id="FactorGraph.to_junction_tree"><a class="viewcode-back" href="../../../models.html#pgmpy.models.FactorGraph.FactorGraph.to_junction_tree">[docs]</a>    <span class="k">def</span> <span class="nf">to_junction_tree</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Create a junction treeo (or clique tree) for a given factor graph.</span>

<span class="sd">        For a given factor graph (H) a junction tree (G) is a graph</span>
<span class="sd">        1. where each node in G corresponds to a maximal clique in H</span>
<span class="sd">        2. each sepset in G separates the variables strictly on one side of</span>
<span class="sd">        edge to other</span>

<span class="sd">        Examples</span>
<span class="sd">        --------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.models import FactorGraph</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.factors.discrete import DiscreteFactor</span>
<span class="sd">        &gt;&gt;&gt; G = FactorGraph()</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([&#39;a&#39;, &#39;b&#39;, &#39;c&#39;])</span>
<span class="sd">        &gt;&gt;&gt; phi1 = DiscreteFactor([&#39;a&#39;, &#39;b&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; phi2 = DiscreteFactor([&#39;b&#39;, &#39;c&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; G.add_factors(phi1, phi2)</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([phi1, phi2])</span>
<span class="sd">        &gt;&gt;&gt; G.add_edges_from([(&#39;a&#39;, phi1), (&#39;b&#39;, phi1),</span>
<span class="sd">        ...                   (&#39;b&#39;, phi2), (&#39;c&#39;, phi2)])</span>
<span class="sd">        &gt;&gt;&gt; mm = G.to_markov_model()</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">mm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">to_markov_model</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">mm</span><span class="o">.</span><span class="n">to_junction_tree</span><span class="p">()</span></div>

<div class="viewcode-block" id="FactorGraph.get_factors"><a class="viewcode-back" href="../../../models.html#pgmpy.models.FactorGraph.FactorGraph.get_factors">[docs]</a>    <span class="k">def</span> <span class="nf">get_factors</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the factors that have been added till now to the graph.</span>

<span class="sd">        If node is not None, it would return the factor corresponding to the</span>
<span class="sd">        given node.</span>

<span class="sd">        Examples</span>
<span class="sd">        --------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.models import FactorGraph</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.factors.discrete import DiscreteFactor</span>
<span class="sd">        &gt;&gt;&gt; G = FactorGraph()</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([&#39;a&#39;, &#39;b&#39;, &#39;c&#39;])</span>
<span class="sd">        &gt;&gt;&gt; phi1 = DiscreteFactor([&#39;a&#39;, &#39;b&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; phi2 = DiscreteFactor([&#39;b&#39;, &#39;c&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; G.add_factors(phi1, phi2)</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([phi1, phi2])</span>
<span class="sd">        &gt;&gt;&gt; G.add_edges_from([(&#39;a&#39;, phi1), (&#39;b&#39;, phi1),</span>
<span class="sd">        ...                   (&#39;b&#39;, phi2), (&#39;c&#39;, phi2)])</span>
<span class="sd">        &gt;&gt;&gt; G.get_factors()</span>
<span class="sd">        &gt;&gt;&gt; G.get_factors(node=phi1)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">node</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">factors</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">factor_nodes</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_factor_nodes</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">node</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">factor_nodes</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;Factors are not associated with the &#39;</span>
                                 <span class="s1">&#39;corresponding node.&#39;</span><span class="p">)</span>
            <span class="n">factors</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">filter</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="nb">set</span><span class="p">(</span><span class="n">x</span><span class="o">.</span><span class="n">scope</span><span class="p">())</span> <span class="o">==</span> <span class="nb">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">neighbors</span><span class="p">(</span><span class="n">node</span><span class="p">)),</span>
                                  <span class="bp">self</span><span class="o">.</span><span class="n">factors</span><span class="p">))</span>
            <span class="k">return</span> <span class="n">factors</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></div>

<div class="viewcode-block" id="FactorGraph.get_partition_function"><a class="viewcode-back" href="../../../models.html#pgmpy.models.FactorGraph.FactorGraph.get_partition_function">[docs]</a>    <span class="k">def</span> <span class="nf">get_partition_function</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the partition function for a given undirected graph.</span>

<span class="sd">        A partition function is defined as</span>

<span class="sd">        .. math:: \sum_{X}(\prod_{i=1}^{m} \phi_i)</span>

<span class="sd">        where m is the number of factors present in the graph</span>
<span class="sd">        and X are all the random variables present.</span>

<span class="sd">        Examples</span>
<span class="sd">        --------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.models import FactorGraph</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.factors.discrete import DiscreteFactor</span>
<span class="sd">        &gt;&gt;&gt; G = FactorGraph()</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([&#39;a&#39;, &#39;b&#39;, &#39;c&#39;])</span>
<span class="sd">        &gt;&gt;&gt; phi1 = DiscreteFactor([&#39;a&#39;, &#39;b&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; phi2 = DiscreteFactor([&#39;b&#39;, &#39;c&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; G.add_factors(phi1, phi2)</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([phi1, phi2])</span>
<span class="sd">        &gt;&gt;&gt; G.add_edges_from([(&#39;a&#39;, phi1), (&#39;b&#39;, phi1),</span>
<span class="sd">        ...                   (&#39;b&#39;, phi2), (&#39;c&#39;, phi2)])</span>
<span class="sd">        &gt;&gt;&gt; G.get_factors()</span>
<span class="sd">        &gt;&gt;&gt; G.get_partition_function()</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">factor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">factors</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">factor</span> <span class="o">=</span> <span class="n">factor_product</span><span class="p">(</span><span class="n">factor</span><span class="p">,</span> <span class="o">*</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">factors</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span>
                                          <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">factors</span><span class="p">))])</span>
        <span class="k">if</span> <span class="nb">set</span><span class="p">(</span><span class="n">factor</span><span class="o">.</span><span class="n">scope</span><span class="p">())</span> <span class="o">!=</span> <span class="nb">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_variable_nodes</span><span class="p">()):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;DiscreteFactor for all the random variables not defined.&#39;</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">factor</span><span class="o">.</span><span class="n">values</span><span class="p">)</span></div>

<div class="viewcode-block" id="FactorGraph.copy"><a class="viewcode-back" href="../../../models.html#pgmpy.models.FactorGraph.FactorGraph.copy">[docs]</a>    <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a copy of the model.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        FactorGraph : Copy of FactorGraph</span>

<span class="sd">        Examples</span>
<span class="sd">        --------</span>
<span class="sd">        &gt;&gt;&gt; import numpy as np</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.models import FactorGraph</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.factors.discrete import DiscreteFactor</span>
<span class="sd">        &gt;&gt;&gt; G = FactorGraph()</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([(&#39;a&#39;, &#39;b&#39;), (&#39;b&#39;, &#39;c&#39;)])</span>
<span class="sd">        &gt;&gt;&gt; phi1 = DiscreteFactor([&#39;a&#39;, &#39;b&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; phi2 = DiscreteFactor([&#39;b&#39;, &#39;c&#39;], [2, 2], np.random.rand(4))</span>
<span class="sd">        &gt;&gt;&gt; G.add_factors(phi1, phi2)</span>
<span class="sd">        &gt;&gt;&gt; G.add_nodes_from([phi1, phi2])</span>
<span class="sd">        &gt;&gt;&gt; G.add_edges_from([(&#39;a&#39;, phi1), (&#39;b&#39;, phi1),</span>
<span class="sd">        ...                   (&#39;b&#39;, phi2), (&#39;c&#39;, phi2)])</span>
<span class="sd">        &gt;&gt;&gt; G_copy = G.copy()</span>
<span class="sd">        &gt;&gt;&gt; G_copy.nodes()</span>
<span class="sd">        [&lt;Factor representing phi(b:2, c:2) at 0xb4badd4c&gt;, &#39;b&#39;, &#39;c&#39;,</span>
<span class="sd">          &#39;a&#39;, &lt;Factor representing phi(a:2, b:2) at 0xb4badf2c&gt;]</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">copy</span> <span class="o">=</span> <span class="n">FactorGraph</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">edges</span><span class="p">())</span>
        <span class="n">copy</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodes</span><span class="p">())</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">factors</span><span class="p">:</span>
            <span class="n">factors_copy</span> <span class="o">=</span> <span class="p">[</span><span class="n">factor</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> <span class="k">for</span> <span class="n">factor</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">factors</span><span class="p">]</span>
            <span class="n">copy</span><span class="o">.</span><span class="n">add_factors</span><span class="p">(</span><span class="o">*</span><span class="n">factors_copy</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">copy</span></div></div>
</pre></div>

          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pgmpy 0.1.2 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2016, Ankur Ankan.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.1.
    </div>
  </body>
</html>